﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T14CommonClass
{
    class Program
    {
        static void Main(string[] args)
        {

            #region Math类
            Console.WriteLine(Math .E);
            Console.WriteLine(Math .PI );
            Console.WriteLine(Math .Abs (-10));
            Console.WriteLine(Math .Floor (20.1));
            Console.WriteLine(Math .Round (20.5));
            Console.WriteLine(Math .Sqrt(16) );

            #endregion

            #region StringBuilder类
            StringBuilder sb = new StringBuilder();
            Console.WriteLine(sb.Capacity );
            Console.WriteLine(sb.MaxCapacity );
            Console.WriteLine(sb.Length );
            string str = "是";
            sb.Append("我");
            sb.Append(str);
            sb.Append("中国人");
            Console.WriteLine(sb.ToString ());
            #endregion

            #region DateTime类
            Console.WriteLine(DateTime .Now );
            Console.WriteLine(DateTime .Today );
            Console.WriteLine(DateTime .Parse ("2018/10/30"));
            Console.WriteLine(DateTime .Now .AddDays (-1).ToShortDateString ());
            Console.WriteLine(DateTime .Now .DayOfWeek );
            string[] day = new string[] {
            "星期天","星期一","星期二","星期三","星期四","星期五","星期六"
            };
            Console.WriteLine(day[Convert .ToInt32 (DateTime .Now .DayOfWeek )]);
            Console.WriteLine(DateTime .Now .ToString ("yyyy年mm月dd日"));

            Console.WriteLine("请输入日期");
            DateTime dt = DateTime.Parse(Console.ReadLine());
            string strWeek = "天一二三四五六".Substring(Convert.ToInt32(dt.DayOfWeek),1);
            Console.WriteLine("今天是{0}年{1}月{2}日 星期{3}，是一年中的第{4}天",
               dt.Year ,dt.Month,dt .Day ,strWeek ,dt.DayOfYear  );
            #endregion

            #region 非泛型集合：集合中元素类型约束性不强
            //数组集合
            ArrayList arrayList = new ArrayList();
            Console.WriteLine(arrayList.Capacity  );
            arrayList.Add(1);
            arrayList.Add("字符串");

            PrintValues(arrayList.GetType() ,arrayList );

            //队列
            Queue queue = new Queue();
            queue.Enqueue("a");
            queue.Enqueue("b");
            PrintValues(queue .GetType (), queue);
            queue.Dequeue();
            PrintValues(queue.GetType(), queue);

            //栈
            Stack stack = new Stack();
            stack.Push("aa");
            stack.Push("bb");
            PrintValues(stack .GetType (), stack);
            stack.Pop();
            PrintValues(stack.GetType(), stack);

            #endregion


            Console.ReadKey();
        }

        public static void PrintValues(Type t, IEnumerable  list)//多态
        {
            StringBuilder sb = new StringBuilder();
            Console.WriteLine(t.ToString ());
            foreach (var item in list )
            {
                sb.Append(item );
                sb.Append("\t");
            }
            Console.WriteLine(sb.ToString ());
        }
    }
}
